//////////////////////////////////////////////////////////////////////////////////
//	Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#include <wx/wx.h>
#include <wx/evtloop.h>
#include "progressdlg.h"

//wxT("Operation in progress, sending command to router")

CProgressDlg::CProgressDlg(wxWindow* pParent, const wxString& strMessage, int nWaitTime):wxProgressDialog( _("Please wait"), strMessage, nWaitTime, pParent, wxPD_APP_MODAL|wxPD_CAN_SKIP  ),
	m_nValue(0)
{
	/*
	wxBoxSizer* szMain = new wxBoxSizer(wxVERTICAL);

	m_pGauge = new wxGauge(this, wxID_ANY, 100);
	m_pGauge->SetMinSize( wxSize(300, 20) );

	szMain->Add(m_pGauge, 1, wxALIGN_CENTER|wxALL|wxGROW, 10);

	wxSizer* sz = CreateStdDialogButtonSizer(wxCANCEL);

	szMain->Add(sz,0, wxALIGN_CENTER|wxALL, 10);

	SetSizer(szMain);

	SetMinSize( wxSize(200, 10) );

	szMain->Fit(this);

	Center();

	wxYieldIfNeeded() ;
	*/
	
	Center();

	SetMinSize( wxSize(300, 20) );

	Start(100);
}

void CProgressDlg::Notify()
{
	if ( m_bRun && IsShown() )
	{
		Pulse();
	}
	else
	{
		Stop();
	}

	if ( WasSkipped() )
	{
		if ( IsRunning() )
		{
			Stop();
		}

		Show(false);
	}
}

CProgressDlg::~CProgressDlg(void)
{
	m_bRun = false;

	if ( IsRunning() )
	{
		Stop();
	}
}

CProgressDlg* CProgressDlg::CreateProgressDlg(wxWindow* pParent, const wxString& strMessage, int nWaitTime)
{
	CProgressDlg* pRes(NULL);

	pRes = new CProgressDlg(pParent, strMessage, nWaitTime);

	//if (pRes) pRes->ShowModal();

	return pRes;
}

